home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / fax / coverpages.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  5.4 KB  |  157 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2003-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. from reportlab.platypus.paragraph import Paragraph
  23. from reportlab.platypus.flowables import Preformatted
  24. from reportlab.platypus.doctemplate import *
  25. from reportlab.platypus import SimpleDocTemplate, Spacer
  26. from reportlab.platypus.tables import Table, TableStyle
  27. from reportlab.lib.pagesizes import letter, legal, A4
  28. from reportlab.lib.units import inch
  29. from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
  30. from reportlab.lib import colors
  31. from time import localtime, strftime
  32. from base import utils
  33.  
  34. PAGE_SIZE_LETTER = 'letter'
  35. PAGE_SIZE_LEGAL = 'legal'
  36. PAGE_SIZE_A4 = 'a4'
  37.  
  38. def escape(s):
  39.     return s.replace("&", "&").replace(">", ">").replace("<", "<")
  40.     
  41.  
  42. def createStandardCoverPage(page_size=PAGE_SIZE_LETTER,
  43.                             total_pages=1, 
  44.                             recipient_name='', 
  45.                             recipient_phone='', 
  46.                             recipient_fax='', 
  47.                             sender_name='', 
  48.                             sender_phone='',
  49.                             sender_fax='', 
  50.                             sender_email='', 
  51.                             regarding='', 
  52.                             message=''):
  53.  
  54.     s = getSampleStyleSheet()
  55.  
  56.     story = []
  57.  
  58.     ps = ParagraphStyle(name="title", 
  59.                         parent=None, 
  60.                         fontName='helvetica-bold',
  61.                         fontSize=36,
  62.                         )
  63.  
  64.     story.append(Paragraph("Fax", ps))
  65.  
  66.     story.append(Spacer(1, inch))
  67.  
  68.     ps = ParagraphStyle(name='normal',
  69.                         fontName='Times-Roman',
  70.                         fontSize=12) 
  71.  
  72.     recipient_name_label = Paragraph("To:", ps)
  73.     recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)
  74.  
  75.     recipient_fax_label = Paragraph("Fax:", ps)
  76.     recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)
  77.  
  78.     recipient_phone_label = Paragraph("Phone:", ps)
  79.     recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)
  80.  
  81.  
  82.     sender_name_label = Paragraph("From:", ps)
  83.     sender_name_text = Paragraph(escape(sender_name[:64]), ps)
  84.  
  85.     sender_phone_label = Paragraph("Phone:", ps)
  86.     sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)
  87.  
  88.     sender_email_label = Paragraph("Email:", ps)
  89.     sender_email_text = Paragraph(escape(sender_email[:64]), ps)
  90.  
  91.  
  92.     regarding_label = Paragraph("Regarding:", ps)
  93.     regarding_text = Paragraph(escape(regarding[:128]), ps)
  94.  
  95.     date_time_label = Paragraph("Date:", ps)
  96.     date_time_text = Paragraph(strftime("%a, %d %b %Y %H:%M:%S (%Z)", localtime()), ps)
  97.  
  98.     total_pages_label = Paragraph("Total Pages:", ps)
  99.     total_pages_text = Paragraph("%d" % total_pages, ps)
  100.  
  101.     data = [[recipient_name_label, recipient_name_text, sender_name_label, sender_name_text],
  102.             [recipient_fax_label, recipient_fax_text, sender_phone_label, sender_phone_text],
  103.             [date_time_label, date_time_text, sender_email_label, sender_email_text],
  104.             [regarding_label, regarding_text, total_pages_label, total_pages_text]]
  105.  
  106.     LIST_STYLE = TableStyle([('LINEABOVE', (0,0), (-1,0), 2, colors.black),
  107.                              ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
  108.                              ('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
  109.                              ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
  110.                              ('VALIGN', (0, 0), (-1, -1), 'TOP'), 
  111.                             ])
  112.  
  113.     t = Table(data, style=LIST_STYLE)
  114.  
  115.     story.append(t)
  116.  
  117.     if message:
  118.  
  119.         MSG_STYLE = TableStyle([('LINEABOVE', (0,0), (-1,0), 2, colors.black),
  120.                                  ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
  121.                                  ('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
  122.                                  ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
  123.                                  ('VALIGN', (0, 0), (-1, -1), 'TOP'),
  124.                                  ('SPAN', (-2, 1), (-1, -1)), 
  125.                                 ])
  126.  
  127.         story.append(Spacer(1, 0.5*inch))
  128.  
  129.         data = [[Paragraph("Comments/Notes:", ps), ''],
  130.                 [Paragraph(escape(message[:2048]), ps), ''],]
  131.                 #[Preformatted(escape(message[:2048]), ps), ''],]
  132.  
  133.         t = Table(data, style=MSG_STYLE)
  134.  
  135.         story.append(t)
  136.  
  137.     if page_size == PAGE_SIZE_LETTER:
  138.         pgsz = letter
  139.     elif page_size == PAGE_SIZE_LEGAL:
  140.         pgsz = legal
  141.     else:
  142.         pgsz = A4
  143.  
  144.     f_fd, f = utils.make_temp_file()
  145.  
  146.     doc = SimpleDocTemplate(f, pagesize=pgsz)
  147.     doc.build(story)
  148.  
  149.     return f
  150.  
  151.  
  152.  
  153. #            { "name" : (function, "thumbnail.png"), ... }    
  154. COVERPAGES = { "basic": (createStandardCoverPage, 'standard_coverpage.png'),
  155.              }
  156.  
  157.